import pymysql


def insert(sql, param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    con.commit()
    cur.close()
    con.close()


def select(sql,param, mode="all", size=0):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql,param)
    if mode == "all":
        return cur.fetchall()
    elif mode == "one":
        return cur.fetchone()
    elif mode == "many":
        return cur.fetchmany(size=size)
    cur.close()
    con.close()

def updata(sql, param):
    con = pymysql.connect(host="localhost", user="root", password="root", database="lt")
    cur = con.cursor()
    cur.execute(sql, param)
    con.commit()
    cur.close()
    con.close()
